package com.itheima.d3_resource;

import java.io.*;

/**
 * 目标：掌握释放资源的方式：try-with-resource
 */
public class Test2 {
    public static void main(String[] args)  {
        File file = new File("day09file-io-app/file/aaa/bbb/img.png");
        File file1 = new File("day09file-io-app/file/aaa/img.png");

        try(FileInputStream fis = new FileInputStream(file);
            FileOutputStream fos = new FileOutputStream(file1);) {

            int leng ;
            byte [] buf = new byte[1024];
            while ((leng = fis.read(buf)) != -1) {
                fos.write(buf);
            }

        }   catch (IOException e) {//自动释放流
            e.printStackTrace();
        }

    }
}
